﻿#define NOMINMAX
#include "client.h"

#include "GuildServiceBasic/proxy/guildservicebasic.service.GuildServiceBasic.proxy.h"
#include "GuildServiceQuery/proxy/guildservicequery.service.GuildServiceQuery.proxy.h"
#include "GuildServiceWelfare/proxy/guildservicewelfare.service.GuildServiceWelfare.proxy.h"
#include "GuildServiceAuth/proxy/guildserviceauth.service.GuildServiceAuth.proxy.h"
#include "GuildServiceBuilding/proxy/guildservicebuilding.service.GuildServiceBuilding.proxy.h"

#include "rpc_defines.h"

#include "GuildApplicationInfo_struct.h"
#include "GuildModuleApplication_struct.h"
#include "GuildModuleBrief_struct.h"
#include "GuildMember_struct.h"
#include "GuildModuleMembers_struct.h"

#include "RegisterArg_struct.h"
#include "RegisterRes_struct.h"
#include "UnregisterNtfData_struct.h"

#include "AnnounceData_struct.h"
#include "AnnounceMsg_struct.h"
#include "ApplyJoinGuildArg_struct.h"
#include "ApplyJoinGuildRes_struct.h"
#include "ChangeGuildAnnounceArg_struct.h"
#include "ChangeGuildAnnounceRes_struct.h"
#include "ChangeGuildDeclarationArg_struct.h"
#include "ChangeGuildDeclarationRes_struct.h"
#include "ChangeGuildIconIdArg_struct.h"
#include "ChangeGuildIconIdRes_struct.h"
#include "ChangeGuildNameArg_struct.h"
#include "ChangeGuildNameRes_struct.h"
#include "CreateGuildArg_struct.h"
#include "CreateGuildRes_struct.h"
#include "GetGuildApplicationArg_struct.h"
#include "GetGuildApplicationRes_struct.h"
#include "GetGuildBriefArg_struct.h"
#include "GetGuildBriefListArg_struct.h"
#include "GetGuildBriefListRes_struct.h"
#include "GetGuildBriefRes_struct.h"
#include "GetGuildMemberArg_struct.h"
#include "GetGuildMemberRes_struct.h"
#include "KickOutGuildMemberArg_struct.h"
#include "KickOutGuildMemberRes_struct.h"
#include "QuitGuildArg_struct.h"
#include "QuitGuildRes_struct.h"
#include "SearchGuildArg_struct.h"
#include "SearchGuildRes_struct.h"
#include "SetAutoApprovalArg_struct.h"
#include "SetAutoApprovalRes_struct.h"
#include "guildservicewelfare/GuildRedEnvelopeBrief_struct.h"
#include "guildservicewelfare/GuildRedEnvelopeBrief_struct.h"
#include "guildservicewelfare/SendGuildRedEnvelopeArg_struct.h"
#include "guildservicewelfare/SendGuildRedEnvelopeRes_struct.h"
#include "guildservicewelfare/LoginArg_struct.h"
#include "guildservicewelfare/LoginRes_struct.h"
#include "guildservicewelfare/LogoutNtfData_struct.h"

#include "guildservicebuilding/BuildingUpgradeArg_struct.h"
#include "guildservicebuilding/BuildingUpgradeRes_struct.h"

#include "box/service_box.hh"
#include "box/service_context.hh"
#include "guild.h"
#include "protobuf/guildservicebasic.service.pb.h"
#include "protobuf/guildservicequery.service.pb.h"
#include "protobuf/guildservicewelfare.service.pb.h"
#include "protobuf/guildservicebuilding.service.pb.h"

Client::Client(kratos::service::ServiceBox &service_box) {
  prx_basic_ =
      service_box.get_context()->get_proxy_sync<GuildServiceBasicProxy>(
          std::string(guild_service::kGuildServicePrefix) +
              std::string(guild_service::kGuildServiceBasicName),
          2000);
  assert(prx_basic_);

  prx_query_ =
      service_box.get_context()->get_proxy_sync<GuildServiceQueryProxy>(
          std::string(guild_service::kGuildServicePrefix) +
              std::string(guild_service::kGuildServiceQueryName),
          2000);
  assert(prx_query_);

  prx_welfare_ =
      service_box.get_context()->get_proxy_sync<GuildServiceWelfareProxy>(
          std::string(guild_service::kGuildServicePrefix) +
              std::string(guild_service::kGuildServiceWelfareName),
          2000);
  assert(prx_welfare_);

  prx_auth_ = service_box.get_context()->get_proxy_sync<GuildServiceAuthProxy>(
      std::string(guild_service::kGuildServicePrefix) +
          std::string(guild_service::kGuildServiceAuthName),
          2000);
  assert(prx_auth_);
  
  prx_building_ = service_box.get_context()->get_proxy_sync<GuildServiceBuildingProxy>(
      std::string(guild_service::kGuildServicePrefix) +
          std::string(guild_service::kGuildServiceBuildingName),
          2000);
  assert(prx_building_);

}

void Client::Register(const std::string &account, const std::string &passwd) {
  std::cout << '\n';
  RegisterArg arg;
  arg.account = account;
  arg.passwd = passwd;

  std::cout << "Register"
            << "\t账号:" << arg.account << "\t密码:" << arg.passwd << '\n';

  try {
    auto res = prx_auth_->Register(arg);
    {
      std::cout << "Register"
                << "\t结果:" << static_cast<int>(res->result)
                << "\t凭证:" << res->token << '\n';
    }

    token_ = res->token;
    role_uuid_ = res->role_uuid;
  } catch (std::exception &ex) {
    std::cerr << "Register exception &:" << ex.what() << std::endl;
  }
}

void Client::Unregister() {
  std::cout << '\n';
  UnregisterNtfData data;
  data.token = token_;

  std::cout << "Unregister"
            << "\t凭证:" << data.token << '\n';

  try {
    prx_auth_->Unregister(data);
    { std::cout << "Unregister" << '\n'; }
  } catch (std::exception &ex) {
    std::cerr << "Unregister exception &:" << ex.what() << std::endl;
  }
}

void Client::CreateGuild(bool use_coro /* = true*/) {
  if (!prx_basic_) {
    return;
  }
  CreateGuildArg arg;
  arg.token = token_;
  arg.name = "guild" + std::to_string(token_);

  std::cout << "CreateGuild"
            << " 凭证:" << arg.token << " 公会名字:" << arg.name << '\n';

  if (use_coro) {
    try {
      auto res = prx_basic_->CreateGuild(arg);
      if (res) {
        std::cout << "CreateGuild"
                  << " 结果:" << static_cast<int>(res->result)
                  << " 公会id:" << res->id << '\n';
        if (res->result == guildservicebasic_cpp::ErrorCode::ERR_SUCCESS) {
          guild_id_ = res->id;
        }
      }
    } catch (std::exception &ex) {
      std::cerr << "CreateGuild exception:" << ex.what() << std::endl;
    }
  } else {
    prx_basic_->CreateGuild(
        arg, [this](const CreateGuildRes &res, rpc::RpcError err) {
          std::cout << "CreateGuild"
                    << " Rpc结果:" << static_cast<uint32_t>(err)
                    << " 结果:" << static_cast<int>(res.result)
                    << " 公会id:" << res.id << '\n';
          if (res.result == guildservicebasic_cpp::ErrorCode::ERR_SUCCESS) {
            guild_id_ = res.id;
          }
        });
  }
}

void Client::GetGuildBrief(bool use_coro /* = true*/) {
  if (!prx_query_) {
    return;
  }
  GetGuildBriefArg arg;
  arg.token = token_;

  std::cout << "GetGuildBrief"
            << " 角色唯一id:" << arg.token << '\n';

  if (use_coro) {
    try {
      auto res = prx_query_->GetGuildBrief(arg);
      if (res) {
        std::cout << "GetGuildBrief"
                  << " 结果:" << static_cast<int>(res->result) << '\n';
      }
    } catch (std::exception &ex) {
      std::cerr << "GetGuildBrief exception:" << ex.what() << std::endl;
    }

  } else {
    prx_query_->GetGuildBrief(
        arg, [](const GetGuildBriefRes &res, rpc::RpcError err) {
          std::cout << "GetGuildBrief"
                    << " Rpc结果:" << static_cast<uint32_t>(err)
                    << " 结果:" << static_cast<int>(res.result) << '\n';
        });
  }
}

void Client::QuitGuild(bool use_coro /* = true*/) {
  if (!prx_basic_) {
    return;
  }
  QuitGuildArg arg;
  arg.token = token_;

  std::cout << "QuitGuild"
            << " 凭证:" << arg.token << '\n';

  if (use_coro) {
      try {
      auto res = prx_basic_->QuitGuild(arg);
      if (res) {
        std::cout << "QuitGuild"
                  << " 结果:" << static_cast<int>(res->result) << '\n';
      }
    } catch (std::exception &ex) {
      std::cerr << "QuitGuild exception:" << ex.what() << std::endl;
    }

  } else {
    prx_basic_->QuitGuild(arg, [](const QuitGuildRes &res, rpc::RpcError err) {
      std::cout << "QuitGuild"
                << " Rpc结果:" << static_cast<uint32_t>(err)
                << "结果:" << static_cast<int>(res.result) << '\n';
    });
  }
}

void Client::GetGuildBriefList(const std::size_t count,
                               bool use_coro /* = true*/) {
  if (!prx_query_) {
    return;
  }
  GetGuildBriefListArg arg;
  arg.token = token_;

  std::cout << "GetGuildBriefList"
            << "凭证:" << arg.token << '\n';

  if (use_coro) {
  } else {
    prx_query_->GetGuildBriefList(
        arg, [this](const GetGuildBriefListRes &res, rpc::RpcError err) {
          for (const auto &it : res.brief_list) {
            std::cout << "GetGuildBriefList"
                      << " Rpc结果:" << static_cast<uint32_t>(err)
                      << " 结果:" << static_cast<int32_t>(res.result)
                      << " brief.name:" << it.name
                      << " brief.level:" << it.level
                      << " brief.chairman_uuid:" << it.chairman_uuid << '\n';
          }
        });
  }
}

void Client::GetGuildMember(const uint64_t member_role_uuid,
                            bool use_coro /* = true*/) {
  if (!prx_query_) {
    return;
  }
  
  GetGuildMemberArg arg;
  arg.token = token_;
  arg.member_uuid = member_role_uuid;

  std::cout << "GetGuildMember"
            << " 凭证:" << arg.token << '\n';

  if (use_coro) {
    try {
      auto res = prx_query_->GetGuildMember(arg);
      if (res) {
        std::cout << "GetGuildMember"
                  << " 结果:" << static_cast<int>(res->result) << '\n';
      }
    } catch (std::exception &ex) {
      std::cerr << "GetGuildMember exception:" << ex.what() << std::endl;
    }

  } else {
    prx_query_->GetGuildMember(
        arg, [this](const GetGuildMemberRes &res, rpc::RpcError err) {
          {
            std::cout << "GetGuildMember"
                      << " Rpc结果:" << static_cast<uint32_t>(err)
                      << " 结果:" << static_cast<int32_t>(res.result)
                      << " member.name:" << res.member.name
                      << " member.role_uuid:" << res.member.role_uuid << '\n';
          }
        });
  }
}

void Client::SearchGuild(const std::string &name,
                         bool use_coro /* = true*/) {
  if (!prx_query_) {
    return;
  }
  
  SearchGuildArg arg;

  arg.token = token_;
  arg.name = name;

  std::cout << "SearchGuild"
            << " 凭证:" << arg.token << " 公会名字:" << arg.name << '\n';

  if (use_coro) {
    try {
      auto res = prx_query_->SearchGuild(arg);
      if (res) {
        std::cout << "SearchGuild"
                  << " 结果:" << static_cast<int32_t>(res->result)
                  << " brief.name:" << res->brief.name
                  << " brief.chairman_uuid:" << res->brief.chairman_uuid << '\n';
      }
    } catch (std::exception &ex) {
      std::cerr << "SearchGuild exception:" << ex.what() << std::endl;
    }
  } else {
    prx_query_->SearchGuild(arg, [this](const SearchGuildRes &res,
                                               rpc::RpcError err) {
      {
        std::cout << "SearchGuild"
                  << " Rpc结果:" << static_cast<uint32_t>(err)
                  << " 结果:" << static_cast<int32_t>(res.result)
                  << " brief.name:" << res.brief.name
                  << " brief.chairman_uuid:" << res.brief.chairman_uuid << '\n';
      }
    });
  }
}

void Client::GetGuildApplication(bool use_coro /* = true*/) {
  if (!prx_query_) {
    return;
  }
  
  GetGuildApplicationArg arg;
  arg.token = token_;

  std::cout << "GetGuildApplication"
            << " 凭证:" << arg.token << '\n';

  if (use_coro) {
    try {
      auto res = prx_query_->GetGuildApplication(arg);
      if (res) {
        for (const auto &it : res->application.application_list) {
          std::cout << "GetGuildApplication"
                    << " 结果:" << static_cast<int32_t>(res->result)
                    << " 角色唯一id:" << it.role_uuid
                    << " 角色性别:" << static_cast<int>(it.role_sex) << '\n';
        }
      }
    } catch (std::exception &ex) {
      std::cerr << "GetGuildApplication exception:" << ex.what() << std::endl;
    }
  } else {
    prx_query_->GetGuildApplication(
        arg,
        [this](const GetGuildApplicationRes &res, rpc::RpcError err) {
          {
            for (const auto &it : res.application.application_list) {
              std::cout << "GetGuildApplication"
                        << " Rpc结果:" << static_cast<uint32_t>(err)
                        << " 结果:" << static_cast<int32_t>(res.result)
                        << " app.role_uuid:" << it.role_uuid
                        << " app.role_sex:" << static_cast<int>(it.role_sex)
                        << '\n';
            }
          }
        });
  }
}

void Client::ApplyJoinGuild(const uint64_t guild_id, const uint64_t invite_role_uuid, 
                            bool use_coro /* = true*/) {
  if (!prx_basic_) {
    return;
  }
  
  ApplyJoinGuildArg arg;

  arg.token = token_;
  arg.guild_id = guild_id;
  arg.invite_role_uuid = invite_role_uuid;

  std::cout << "ApplyJoinGuild"
            << " 凭证:" << arg.token << '\n';

  if (use_coro) {
    try {
      auto res = prx_basic_->ApplyJoinGuild(arg);
      if (res) {
        std::cout << "ApplyJoinGuild"
                  << " 结果:" << static_cast<int32_t>(res->result) << '\n';
      }
    } catch (std::exception &ex) {
      std::cerr << "ApplyJoinGuild exception:" << ex.what() << std::endl;
    }
  } else {
    prx_basic_->ApplyJoinGuild(
        arg, [this](const ApplyJoinGuildRes &res, rpc::RpcError err) {
          {
            std::cout << "ApplyJoinGuild"
                      << " Rpc结果:" << static_cast<uint32_t>(err)
                      << " 结果:" << static_cast<int32_t>(res.result) << '\n';
          }
        });
  }
}

void Client::KickOutGuildMember(const uint64_t kick_role_uuid,
                                bool use_coro /* = true*/) {
  if (!prx_basic_) {
    return;
  }
  
  KickOutGuildMemberArg arg;

  arg.token = token_;
  arg.kick_role_uuid = kick_role_uuid;

  std::cout << "KickOutGuildMember"
            << " 凭证:" << arg.token 
            << " 踢出角色唯一id:" << arg.kick_role_uuid << '\n';

  if (use_coro) {
    try {
      auto res = prx_basic_->KickOutGuildMember(arg);
      if (res) {
        std::cout << "KickOutGuildMember"
                  << " 结果:" << static_cast<int32_t>(res->result) << '\n';
      }
    } catch (std::exception &ex) {
      std::cerr << "KickOutGuildMember exception:" << ex.what() << std::endl;
    }
  } else {
    prx_basic_->KickOutGuildMember(
        arg,
        [this](const KickOutGuildMemberRes &res, rpc::RpcError err) {
          {
            std::cout << "KickOutGuildMember"
                      << " Rpc结果:" << static_cast<uint32_t>(err)
                      << " 结果:" << static_cast<int32_t>(res.result) << '\n';
          }
        });
  }
}

void Client::SetAutoApproval(bool is_auto_approval, bool use_coro /* = true*/) {
  if (!prx_basic_) {
    return;
  }
  
  SetAutoApprovalArg arg;

  arg.token = token_;
  arg.is_auto_approval = is_auto_approval;

  std::cout << "SetAutoApproval"
            << " 凭证:" << arg.token << " 是否自动同意:" << arg.is_auto_approval
            << '\n';

  if (use_coro) {
    try {
      auto res = prx_basic_->SetAutoApproval(arg);
      if (res) {
        std::cout << "SetAutoApproval"
                  << " 结果:" << static_cast<int32_t>(res->result) << '\n';
      }
    } catch (std::exception &ex) {
      std::cerr << "SetAutoApproval exception:" << ex.what() << std::endl;
    }
  } else {

    prx_basic_->SetAutoApproval(
        arg, [this](const SetAutoApprovalRes &res, rpc::RpcError err) {
          {
            std::cout << "SetAutoApproval"
                      << " Rpc结果:" << static_cast<uint32_t>(err)
                      << " 结果:" << static_cast<int32_t>(res.result) << '\n';
          }
        });
  }
}

void Client::ChangeGuildIconId(const uint32_t icon_id,
                               bool use_coro /* = true*/) {
  if (!prx_basic_) {
    return;
  }
  
  ChangeGuildIconIdArg arg;
  arg.token = token_;
  arg.icon_id = icon_id;

  std::cout << "ChangeGuildIconId"
            << " 角色唯一id:" << arg.token << " 图标id:" << arg.icon_id << '\n';

  if (use_coro) {
    try {
      auto res = prx_basic_->ChangeGuildIconId(arg);
      if (res) {
        std::cout << "ChangeGuildIconId"
                  << " 结果:" << static_cast<int32_t>(res->result) << '\n';
      }
    } catch (std::exception &ex) {
      std::cerr << "ChangeGuildIconId exception:" << ex.what() << std::endl;
    }

  } else {
   prx_basic_->ChangeGuildIconId(
        arg, [this](const ChangeGuildIconIdRes &res, rpc::RpcError err) {
          {
            std::cout << "ApplyJoinGuild"
                      << " Rpc结果:" << static_cast<uint32_t>(err)
                      << " 结果:" << static_cast<int32_t>(res.result) << '\n';
          }
        });
  }
}

void Client::ChangeGuildName(const std::string &name,
                             bool use_coro /* = true*/) {
  if (!prx_basic_) {
    return;
  }
  
  ChangeGuildNameArg arg;
  arg.token = token_;
  arg.name = name;

  std::cout << "ChangeGuildName"
            << " 角色唯一id:" << arg.token << " 公会名字:" << arg.name << '\n';

  if (use_coro) {
    try {
      auto res = prx_basic_->ChangeGuildName(arg);
      if (res) {
        std::cout << "ChangeGuildName"
                  << " 结果:" << static_cast<int32_t>(res->result) << '\n';
      }
    } catch (std::exception &ex) {
      std::cerr << "ChangeGuildName exception:" << ex.what() << std::endl;
    }
  } else {
    prx_basic_->ChangeGuildName(
        arg, [this](const ChangeGuildNameRes &res, rpc::RpcError err) {
          {
            std::cout << "ChangeGuildName"
                      << " Rpc结果:" << static_cast<uint32_t>(err)
                      << " 结果:" << static_cast<int32_t>(res.result) << '\n';
          }
        });
  }
}

void Client::ChangeGuildDeclaration(const std::string &declaration,
                                    bool use_coro /* = true*/) {
  if (!prx_basic_) {
    return;
  }
  
  ChangeGuildDeclarationArg arg;
  arg.token = token_;
  arg.declaration = declaration;

  std::cout << "ChangeGuildDeclaration"
            << " 凭证:" << arg.token << " 公会宣言:" << arg.declaration << '\n';

  if (use_coro) {
    try {
      auto res = prx_basic_->ChangeGuildDeclaration(arg);
      if (res) {
        std::cout << "ChangeGuildDeclaration"
                  << " 结果:" << static_cast<int32_t>(res->result) << '\n';
      }
    } catch (std::exception &ex) {
      std::cerr << "ChangeGuildDeclaration exception:" << ex.what()
                << std::endl;
    }
  } else {
    prx_basic_->ChangeGuildDeclaration(
        arg,
        [this](const ChangeGuildDeclarationRes &res, rpc::RpcError err) {
          {
            std::cout << "ChangeGuildDeclaration"
                      << " Rpc结果:" << static_cast<uint32_t>(err)
                      << " 结果:" << static_cast<int32_t>(res.result) << '\n';
          }
        });
  }
}

void Client::ChangeGuildAnnounce(const std::string &announce,
                                 bool use_coro /* = true*/) {
  if (!prx_basic_) {
    return;
  }
  ChangeGuildAnnounceArg arg;
  arg.token = token_;
  arg.announce = announce;

  std::cout << "ChangeGuildAnnounce"
            << " 凭证:" << arg.token << " 公会通知:" << arg.announce << '\n';

  if (use_coro) {
    try {
      auto res = prx_basic_->ChangeGuildAnnounce(arg);
      if (res) {
        std::cout << "ChangeGuildAnnounce"
                  << " 结果:" << static_cast<int32_t>(res->result) << '\n';
      }
    } catch (std::exception &ex) {
      std::cerr << "ChangeGuildAnnounce exception:" << ex.what()
                << std::endl;
    }
  } else {
    prx_basic_->ChangeGuildAnnounce(
        arg,
        [this](const ChangeGuildAnnounceRes &res, rpc::RpcError err) {
          {
            std::cout << "ChangeGuildAnnounce"
                      << " Rpc结果:" << static_cast<uint32_t>(err)
                      << " 结果:" << static_cast<int32_t>(res.result) << '\n';
          }
        });
  }
}

void Client::SendGuildRedEnvelope(bool use_coro /* = true*/) {
  if (!prx_welfare_) {
    return;
  }

  SendGuildRedEnvelopeArg arg;
  arg.token = token_;
  arg.brief.content = std::string("Red") + std::to_string(arg.token);
  arg.brief.type = guildservicewelfare_cpp::RedEnvelopeType::RED_ENVELOPE_TYPE_ORDINARY;
  arg.brief.money = 100;
  arg.brief.count = 2;

  std::cout << "SendGuildRedEnvelope"
            << "\t凭证:" << arg.token
            << "\t红包名字:" << arg.brief.content
            << "\t红包类型:" << static_cast<int>(arg.brief.type)
            << "\t红包金额:" << arg.brief.money
            << "\t红包数量:" << arg.brief.count << '\n';

  if (use_coro) {
    try {
      auto res = prx_welfare_->SendGuildRedEnvelope(arg);
      if (res) {
        std::cout << "SendGuildRedEnvelope"
                  << "\t结果:" << static_cast<int>(res->result)
                  << "\t红包uid:" << res->red_envelope_uid << '\n';
      }
    } catch (std::exception &ex) {
      std::cerr << "SendGuildRedEnvelope exception:" << ex.what() << std::endl;
    }
  } else {
    prx_welfare_->SendGuildRedEnvelope(
        arg, [this](const SendGuildRedEnvelopeRes &res, rpc::RpcError err) {
          {
            std::cout << "SendGuildRedEnvelope"
                      << "\t结果:" << static_cast<int>(res.result)
                      << "\t红包uid:" << res.red_envelope_uid << '\n';
          }
        });
  }
}

void Client::LoginWelfare(bool use_coro /* = true*/) {
  if (!prx_welfare_) {
    return;
  }
  LoginArg arg;
  arg.token = token_;

  std::cout << "LoginWelfare"
            << "\t凭证:" << arg.token << '\n';

  if (use_coro) {
    try {
      auto res = prx_welfare_->Login(arg);
      if (res) {
        std::cout << "LoginWelfare"
                  << "\t结果:" << static_cast<int>(res->result) << '\n';
      }
    } catch (std::exception &ex) {
      std::cerr << "LoginWelfare exception:" << ex.what() << std::endl;
    }
  } else {
    prx_welfare_->Login(arg, [this](const LoginRes &res, rpc::RpcError err) {
      {
        std::cout << "LoginWelfare"
                  << "\t结果:" << static_cast<int>(res.result) << '\n';
      }
    });
  }
}

void Client::LogoutWelfare() {
  if (!prx_welfare_) {
    return;
  }
  LogoutNtfData data;
  data.token = token_;

  std::cout << "LogoutWelfare"
            << "\t凭证:" << data.token << '\n';
  try {
    prx_welfare_->Logout(data);
  } catch (std::exception &ex) {
    std::cerr << "LogoutWelfare exception:" << ex.what() << std::endl;
  }
}

void Client::BuildingUpgrade(bool use_coro/* = true*/) {
  if (!prx_building_) {
    return;
  }
  BuildingUpgradeArg arg;
  arg.token = token_;
  arg.building_id = 0;
  arg.level = 1;

  std::cout << "BuildingUpgrade"
            << "\t凭证:" << arg.token << '\n';
  if (use_coro) {
    try {
      auto res = prx_building_->BuildingUpgrade(arg);
      if (res) {
        std::cout << "BuildingUpgrade"
                  << "\t结果:" << static_cast<int>(res->result) << '\n';
      }
    } catch (std::exception &ex) {
      std::cerr << "BuildingUpgrade exception:" << ex.what() << std::endl;
    }
  } else {
    prx_building_->BuildingUpgrade(arg, [this](const BuildingUpgradeRes &res, rpc::RpcError err) {
      {
        std::cout << "BuildingUpgrade"
                  << "\t结果:" << static_cast<int>(res.result) << '\n';
      }
    });
  }
}
